package com.training.java.module2;

import java.util.Scanner;
import java.util.StringTokenizer;


public class QuestionWithTextAnswer extends Question {

    private String correctAnswer;

    public QuestionWithTextAnswer(String unparsedString) {
        fillQuestionInformation(unparsedString);
    }

    private void fillQuestionInformation(String unparsedString) {

        StringTokenizer stringTokenizer = new StringTokenizer(unparsedString, "|");
        stringTokenizer.nextToken();
        setQuestion(stringTokenizer.nextToken());
        correctAnswer = stringTokenizer.nextToken();
    }

    private String readCustomerAnswer() {

        Scanner inputScanner = new Scanner( System.in );

        System.out.println("Введите ваш ответ:");

        String customerAnswer = inputScanner.next();

        return customerAnswer;
    }

    public boolean isCorrectAnswer() {
        String customerAnswer = readCustomerAnswer().toLowerCase();
        correctAnswer  = correctAnswer.toLowerCase();
        if(customerAnswer.equals(correctAnswer)) {
            return true;
        }
        return false;
    }
    public String  toString() {
        return String.format("%s%n", getQuestion());
    }

}
